#include "color_transition.h"

#include <string>

using namespace std;

ColorTransition::ColorTransition( Animation* _src,
                                  const QColor& start,
                                  const QColor& end,
                                  TransitionType _ttype,
                                  int startTime,
                                  int endTime )
{
    r = g = b = a = 0;
    ttype = _ttype;

    if( endTime == -1 ) endTime = _src->GetDuration();

    switch( ttype )
    {
    case RedOnly:
        graph.AddSimpleProperty( "red", r );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "red",
                           start.red(), end.red() );
        break;
    case GreenOnly:
        graph.AddSimpleProperty( "green", g );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "green",
                           start.green(), end.green() );
        break;
    case BlueOnly:
        graph.AddSimpleProperty( "blue", b );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "blue",
                           start.blue(), end.blue() );
        break;
    case AlphaOnly:
        graph.AddSimpleProperty( "alpha", a );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "alpha",
                           start.alpha(), end.alpha() );
        break;
    case AllChannels:
        string names[4] = { "red", "green", "blue", "alpha" };
        int* val[4] = { &r, &g, &b, &a };
        graph.AddSimpleProperties( names, val, 4 );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "red",
                           start.red(), end.red() );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "green",
                           start.green(), end.green() );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "blue",
                           start.blue(), end.blue() );
        graph.AddInterpolator( _src->GetTime(), startTime, endTime, "alpha",
                           start.alpha(), end.alpha() );
        break;
    }
}

ColorTransition::~ColorTransition( void )
{
    ;
}

void ColorTransition::GetColor( QColor& toFill )
{
    toFill.setRed( r );
    toFill.setGreen( g );
    toFill.setBlue( b );
    toFill.setAlpha( a );
}

